package com.example.demo.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.dao.ClientTokenDao;
import com.example.demo.entity.ClientToken;
import com.example.demo.entity.TToken;

@Service
public class ClientTokenService {
	
	@Autowired
	ClientTokenDao clientTokenDao;
	
	public ClientToken findByAppId(String appid) {
		ClientToken token = clientTokenDao.findAllByAppid(appid);
		if (token == null) {
			return null;
		}
		return token;
	}
	
	
	public long modifyToken(String appid, String tokenStr, long exprie) {
		ClientToken token = clientTokenDao.findAllByAppid(appid);
		token.setExpire(exprie);
		token.setToken(tokenStr);

		try {
			clientTokenDao.save(token);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return token.getExpire();
	}
}
